class Solution {
    public int[] twoSum(int[] nums, int target) {
        int len = nums.length;
        int left = 0;
        int right = len-1;
        while(left < right) {
            int s = nums[left] + nums[right];
            if(target < s) {
                right-- ;
            }else if (target > s) {
                left++ ;
            }else {
                break;
            }
        }
        return new int[]{nums[left],nums[right]};
    }
}